<?php
$s="计算机012ABC";
//strlen求字符串长度
echo strlen($s),"\n";
// trim、ltrim、rtrim 删空白
$s="     \t\t  How are you ?    \t\t  \t";
echo "[$s]\n";
echo "[",trim($s),"]\n"; //删除两端的空白
echo "[",ltrim($s),"]\n"; //删除左侧的空白
echo "[",rtrim($s),"]\n"; // //删除右侧的空白
$s="__:,Hi:::,__";
echo "[",trim($s, "_:,"),"]\n";  //删除两端指定的那些字符

//strpos求子串在父串中出现的位置，找到返回整数，否则返回false
echo strpos("How are you?","o"),"\n"; //1
echo strpos("How are you?","o", 3),"\n"; //9
var_dump(strpos("How are you?","oo" )); //bool(false)
if(strpos("How are you?","H" )!==false){ //必须完全比较SF是false
    echo "find\n";
}else{
    echo "No find\n";
}
//bin2hex将字符串的每个字节转换为两个16进制位
echo bin2hex("计算机012ABC"),"\n"; //e8aea1e7ae97e69cba303132414243
//chunk_split 将字符串分隔成小块
echo chunk_split("1234567",2,"*"),"\n"; // 12*34*56*7*
//str_replace字符串替换
echo str_replace('o','***','How are you?'),"\n"; //H***w are y***u?
//str_repeat重复若干次
echo '[',str_repeat('Ok',3),"]\n"; // [OkOkOk]
echo '[',str_repeat('Ok',0),"]\n"; // []
//ord字符转换为代码点, chr代码点转换为字符
echo ord('ABCD');  // 显示第一个字符A的ASCII码值 65
echo chr(65),"\n";
//join将数组拼接成一个字符串
echo join(['Hi','Zhangsan',"\n"]); //HiZhangsan
echo join(', ', [123,456,789,"\n"]); //123, 456, 789,
//strtoupper\strtolower转换为大小写
echo strtoupper("How are you?\n"); //HOW ARE YOU?
echo strtolower("How are you?\n"); //how are you?
//printf、sprintf格式化数据
printf("%d + %d = %d\n", 111, 222, 111+222); //111 + 222 = 333
printf("[%d] [%5d] [%-5d] [%05d] [%X] [%04X]\n", 26,26,26,26,26,26); //[26] [   26] [26   ] [00026] [1A] [001A]
echo sprintf("%d plus %d equals %d.\n",12,6, 12+6); //12 plus 6 equals 18.
//str_starts_with、str_ends_with是否以子串开头或结尾
var_dump(str_starts_with("How are you?","How")); //bool(true)
var_dump(str_starts_with("How are you?","how")); //bool(false)
//substr取子串
echo substr("Hello",2),"\n"; //llo
echo substr("Hello",2,2),"\n"; //ll
echo substr("Hello",-2),"\n"; //lo
//icov字符串改变编码
$s1="abc计算机";
echo strlen($s1),"\n"; //12
$s2=iconv("UTF-8","gbk",$s1);
echo strlen($s2),"\n"; //9
echo "[$s1], [$s2]\n"; //[abc计算机], [abc�����]

